spb/chat-spboucher-ai
Public
1import { guarded, json } from "@/lib/api";2import { readAttachment, deleteAttachment, getAttachment } from "@/lib/storage";34export const GET = guarded<{ id: string }>(async (req, { params }) => {5 if (req.nextUrl.searchParams.get("meta") === "1") { const a = await getAttachment(params.id); return a ? json({ attachment: { ...a, extracted_text: a.extracted_text?.slice(0, 20_000) } }) : json({ error: "Introuvable" }, { status: 404 }); }6 const a = await readAttachment(params.id);7 if (!a) return json({ error: "Introuvable" }, { status: 404 });8 const download = req.nextUrl.searchParams.get("download") === "1";9 return new Response(new Uint8Array(a.data), { headers: { "content-type": a.mime, "content-length": String(a.data.length), "cache-control": "private, max-age=3600", "content-disposition": `${download ? "attachment" : "inline"}; filename*=UTF-8''${encodeURIComponent(a.name)}`, "x-content-type-options": "nosniff" } });10});1112export const DELETE = guarded<{ id: string }>(async (_req, { params }) => { await deleteAttachment(params.id); return json({ ok: true }); });13